//
//  SNormalFunction.m
//  LSCodeLibrary
//
//  Created by Samuel on 15/4/1.
//  Copyright (c) 2015年 Samuel. All rights reserved.
//

#import "SNormalFunction.h"

@implementation SNormalFunction

#pragma mark 判断系统是否为IOS7以上
+(BOOL)SystemVersion{
    return ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0)?YES:NO;
}
#pragma mark 检查手机号格式
+(BOOL)isMobileCheck:(NSString *)string
{
    NSString *Regex = @"^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\\d{8}$";
    NSPredicate *Test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
    return [Test evaluateWithObject:string];
}
#pragma mark String非空判断
+(BOOL)isEmpty:(NSString *)string{
    if (!string)
    {
        return true;
    }
    else
    {
        //A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        //Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
        NSString *trimedString = [string stringByTrimmingCharactersInSet:set];
        if ([trimedString length] == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
#pragma mark 字符串截取
+ (NSString*)ReplacingStringFrom:(NSString*)string
                 andTargetString:(NSString*)tarString;
{
    NSString *newString = string;
    NSRange range;
    while ((range = [newString rangeOfString:@"< [^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound){
        newString = [newString stringByReplacingCharactersInRange:range withString:@""];
    }
    NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n" options:0 error:nil];
    newString=[regularExpretion stringByReplacingMatchesInString:newString options:NSMatchingReportProgress range:NSMakeRange(0, newString.length) withTemplate:@""];
    newString = [newString stringByReplacingOccurrencesOfString:tarString withString:@""];
    return newString;
}
#pragma mark 加密手机号
+(NSString *)EncryptMobileNumber:(NSString *)string
{
    NSMutableString *num= [NSMutableString string];
    NSString *src = string;
    for (int i=0; i<src.length; i++)
    {
        if (i>2&&i<7)
        {
            [num appendString:@"*"];
        }
        else
        {
            NSString *single= [src substringWithRange:NSMakeRange(i,1)];
            [num appendString:single];
        }
    }
    return num;
}
@end
